package com.atguigu.flink04;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/2/22
 * 该案例演示了合流算子
 * union
 *      可以对多条流进行合并
 *      参与合并的流数据类型必须一致
 */
public class Flink05_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        env.setParallelism(1);

        //从8888端口读取数据
        DataStreamSource<String> ds1 = env.socketTextStream("hadoop102", 8888);
        //从8889端口读取数据
        DataStreamSource<String> ds2 = env.socketTextStream("hadoop102", 8889);
        //从指定的元素中读取数据
        SingleOutputStreamOperator<String> ds3 = env.fromElements(1, 2, 3, 4).map(value -> value + "");
        //ds1.union(ds2).union(ds3);
        ds1
                .union(ds2,ds3)
                .print();

        env.execute();

    }
}
